﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using LocalSettings;
using QuickTasks.ViewModels.Data;
using Microsoft.Advertising.Mobile.UI;

namespace QuickTasks
{
    public partial class LinkSettings : PhoneApplicationPage
    {
       
        public LinkSettings()
        {
            InitializeComponent();
          
           
        }
   
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (IsolatedSettings.getSettingsBoolValue("runUnderLock"))
            {
                lockToggleSwitch.Content = "On";
                lockToggleSwitch.IsChecked = true;
            }
            else
            {
                lockToggleSwitch.Content = "Off";
                lockToggleSwitch.IsChecked = false;
            }
            if (IsolatedSettings.getSettingsStringValue("RefreshRate") != null)
            {
                tbxRefreshRate.Text = IsolatedSettings.getSettingsStringValue("RefreshRate");
            }
        }

        private void lockToggleSwitch_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!ApplicationIdleModeHelper.Current.HasUserAgreedToRunUnderLock)
                {

                    ApplicationIdleModeHelper.Current.HasUserAgreedToRunUnderLock = true;
                    lockToggleSwitch.Content = "On";
                    IsolatedSettings.saveSettings("runUnderLock", "true");


                    ApplicationIdleModeHelper.Current.RunsUnderLock = true;

                }
                else
                {
                    lockToggleSwitch.Content = "On";
                    ApplicationIdleModeHelper.Current.RunsUnderLock = true;

                }
            }
            catch (Exception ex)
            {

                Exceptions.SaveOrSendExceptions("Exception in lockToggleSwitch_Checked event In LinkSettings.xaml page", ex);
            }                 
           
        }

        private void lockToggleSwitch_Unchecked(object sender, RoutedEventArgs e)
        {
            try
            {
                lockToggleSwitch.Content = "Off";
                ApplicationIdleModeHelper.Current.RunsUnderLock = false;
                IsolatedSettings.saveSettings("runUnderLock", "false");
            }
            catch (Exception ex)
            {

                Exceptions.SaveOrSendExceptions("Exception in lockToggleSwitch_Unchecked event In LinkSettings.xaml page", ex);
            }
        }

        private void tbxRefreshRate_TextChanged(object sender, TextChangedEventArgs e)
        {
            IsolatedSettings.saveSettings("RefreshRate", tbxRefreshRate.Text);
        }

        //private void ApplicationBarstartButton_Click(object sender, EventArgs e)
        //{

        //   NavigationService.Navigate(new Uri("/Views/Help/HelpMenu.xaml", UriKind.Relative));
        //}
    }
}